# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=setuptools-rust
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.11.1
pkgrel=1
pkgdesc="Compile and distribute Python extensions written in rust as easily as if they were written in C (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/PyO3/setuptools-rust'
msys2_references=(
  'archlinux: python-setuptools-rust'
  'purl: pkg:pypi/setuptools-rust'
)
license=('spdx:MIT')
depends=("${MINGW_PACKAGE_PREFIX}-rust"
         "${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-semantic-version"
         "${MINGW_PACKAGE_PREFIX}-python-setuptools")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm")
source=("https://pypi.org/packages/source/${_realname::1}/${_realname/-/_}/${_realname/-/_}-${pkgver}.tar.gz")
sha256sums=('7dabc4392252ced314b8050d63276e05fdc5d32398fc7d3cce1f6a6ac35b76c0')

prepare() {
  cp -r "${_realname/-/_}-${pkgver}" "python-build-${MSYSTEM}"

  export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
}

build() {
  cd "python-build-${MSYSTEM}"

  python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 "${srcdir}/${_realname/-/_}-${pkgver}/LICENSE" \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
